using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AlphaWebsite.Models;

namespace AlphaWebsite.Controllers
{   
    public class WeddingHouseholdsController : Controller
    {
		private readonly IUserWeddingPlanRepository userweddingplanRepository;
		private readonly IWeddingHouseholdsRepository weddinghouseholdsRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public WeddingHouseholdsController() : this(new UserWeddingPlanRepository(), new WeddingHouseholdsRepository())
        {
        }

        public WeddingHouseholdsController(IUserWeddingPlanRepository userweddingplanRepository, IWeddingHouseholdsRepository weddinghouseholdsRepository)
        {
			this.userweddingplanRepository = userweddingplanRepository;
			this.weddinghouseholdsRepository = weddinghouseholdsRepository;
        }

        //
        // GET: /WeddingHouseholds/

        public ViewResult Index()
        {
            return View(weddinghouseholdsRepository.AllIncluding(weddinghouseholds => weddinghouseholds.UserWeddingPlan));
        }

        //
        // GET: /WeddingHouseholds/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(weddinghouseholdsRepository.Find(id));
        }

        //
        // GET: /WeddingHouseholds/Create

        public ActionResult Create()
        {
			ViewBag.PossibleUserWeddingPlans = userweddingplanRepository.All;
            return View();
        } 

        //
        // POST: /WeddingHouseholds/Create

        [HttpPost]
        public ActionResult Create(WeddingHouseholds weddinghouseholds)
        {
            if (ModelState.IsValid) {
                weddinghouseholdsRepository.InsertOrUpdate(weddinghouseholds);
                weddinghouseholdsRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleUserWeddingPlans = userweddingplanRepository.All;
				return View();
			}
        }
        
        //
        // GET: /WeddingHouseholds/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleUserWeddingPlans = userweddingplanRepository.All;
             return View(weddinghouseholdsRepository.Find(id));
        }

        //
        // POST: /WeddingHouseholds/Edit/5

        [HttpPost]
        public ActionResult Edit(WeddingHouseholds weddinghouseholds)
        {
            if (ModelState.IsValid) {
                weddinghouseholdsRepository.InsertOrUpdate(weddinghouseholds);
                weddinghouseholdsRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleUserWeddingPlans = userweddingplanRepository.All;
				return View();
			}
        }

        //
        // GET: /WeddingHouseholds/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(weddinghouseholdsRepository.Find(id));
        }

        //
        // POST: /WeddingHouseholds/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            weddinghouseholdsRepository.Delete(id);
            weddinghouseholdsRepository.Save();

            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                userweddingplanRepository.Dispose();
                weddinghouseholdsRepository.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

